<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<div>
  <div fxFlex="70">
    <form (ngSubmit)="update()" fxLayout="column" #groupForm="ngForm">
      <div class="gv-form-section">
        <mat-form-field appearance="outline" floatLabel="always">
          <mat-label>Name</mat-label>
          <input matInput type="text" placeholder="Group name" #name="ngModel" name="name" [(ngModel)]="group.name" required [readonly]="!editMode">
          <mat-hint>The name of the Group.</mat-hint>
          <mat-error *ngIf="name.errors?.required">Enter name</mat-error>
        </mat-form-field>
        <mat-form-field appearance="outline" floatLabel="always">
          <mat-label>Description</mat-label>
          <input matInput type="text" placeholder="Description" #name="ngModel" name="description" [(ngModel)]="group.description" [readonly]="!editMode">
          <mat-hint>The description of the Group.</mat-hint>
        </mat-form-field>
      </div>
      <div fxLayout="row" *ngIf="editMode">
        <button mat-raised-button color="primary" [disabled]="!groupForm.valid || groupForm.pristine" type="submit">SAVE</button>
      </div>
    </form>
    <div class="gv-page-delete-zone" fxLayout="column" *ngIf="deleteMode">
      <p>This operation cannot be undone.</p>
      Group will be deleted and members will be removed from this group.
      <div class="gv-page-delete-button" fxLayout="row">
        <span fxFlex></span>
        <button mat-raised-button color="warn" (click)="delete($event)">DELETE</button>
      </div>
    </div>
  </div>
  <div class="gv-page-description" fxFlex>
    <h3>Group activities</h3>
    <div class="gv-page-description-content">
      <mat-list>
        <mat-list-item>
          <mat-icon mat-list-icon>alarm_on</mat-icon>
          <h4 matLine>Created at</h4>
          <p matLine>{{group.createdAt | humanDate}}</p>
        </mat-list-item>
        <mat-list-item>
          <mat-icon mat-list-icon>alarm</mat-icon>
          <h4 matLine>Last update</h4>
          <p matLine>{{group.updatedAt | humanDate}}</p>
        </mat-list-item>
        <mat-list-item>
          <mat-icon mat-list-icon>people</mat-icon>
          <h4 matLine>Members count</h4>
          <p matLine><span *ngIf="!group.members || group.members.length == 0; else members">No member</span><ng-template #members>{{group.members.length}} members</ng-template></p>
        </mat-list-item>
      </mat-list>
    </div>
  </div>
</div>
